<meta charset="utf-8">
<base href="http://localhost">
<?php
//判断cookie里是否存在帐号密码 如果存在获取
$username="";
$password="";
if(isset($_COOKIE["username"])){
	//获取cookie里的值
	$username=$_COOKIE["username"];
}
if(isset($_COOKIE["password"])){
	$password=$_COOKIE["password"];
}
?>
<style type="text/css">
	h3{ position: absolute; top: 110px; left: 530px; }
	form{ position: absolute; top: 200px; left: 500px;}
	.log{ margin-left: 40px; }
	.reg{ margin-left: 50px; }
</style>
<h3>欢迎登录图书管理系统</h3>
<form method="post" action="">
	用户名:<input type="text" name="username" value="<?php echo $username;?>"><br/><br/>
	密&nbsp&nbsp&nbsp码:<input type="password" name="password" value="<?php echo $password;?>"><br/><br/>
	<input class="log" type="submit" name="submit" value="登录">
	<input class="reg" type="button" onclick="window.location.href='index.php/welcome/register'" value="注册">
</form>
<?php
if(isset($_POST["submit"])&&$_POST["submit"]=="登录"){
	//是登录按钮触发的事件
	$username=$_POST["username"];
	$password=$_POST["password"];
	//查询数据库 看看是否存在匹配的用户
	$selectusersql="select * from userinfos where username='$username' and password='$password'";
	include_once("database.php");
	$result=@mysql_query($selectusersql) or die("登录失败:".mysql_error()."<br/>");
	if(mysql_num_rows($result)>0){
		//输入的用户名和密码是正确的
		//写cookie信息
		setcookie("username",$username,time()+60*60);
		//跳转页面到主界面
		header("refresh:1;url=index");
	}else{
		//输入的用户名和密码不存在
	    echo "<script>alert(\"用户名或密码错误!\");</script>";
	}
}
?>